#include "stuff.h"

#ifndef CONTROL_H
#define CONTROL_H

namespace Input
{
	enum ControlType
	{
		KEY_DOWN,
		KEY_PRESS,
		MOUSE_DOWN,
		MOUSE_PRESS
	};

	class Control
	{
		protected:
			int index;
			void (*action)();

		public:
			Control() {};
			Control(int index, void f())
			{
				this->index = index;
				this->action = f;
			}
			virtual void update() { std::cout << "parent" << std::endl; };
	};

	class KeyDown : public Control
	{
		public:
			KeyDown() { };
			KeyDown(int index, void f()) : Control(index, f) {};

			virtual void update()
			{
				std::cout << "child" << std::endl;

				if(glfwGetKey(index))
				{
					action();
				}
			}
	};

	class KeyPress : public Control
	{
		private:
			bool wasDown;

		public:
			KeyPress() { };
			KeyPress(int index, void f()) : Control(index, f), wasDown(false) {};

			virtual void update()
			{
				std::cerr << "child" << std::endl;

				if(glfwGetKey(index) && !wasDown)
				{
					OutputDebugString("right before action call/n");
					action();
					wasDown = true;
				}
				else
				{
					wasDown = false;
				}
			}
	};

	class MouseDown : public Control
	{
		public:
			MouseDown() {};
			MouseDown(int index, void f()) : Control(index, f) {};

			void update()
			{
				std::cout << "child" << std::endl;

				if(glfwGetMouseButton(index))
				{
					action();
				}
			}
	};

	class MousePress : public Control
	{
		private:
			bool wasDown;
		public:
			MousePress() {};
			MousePress(int index, void f()) : Control(index, f), wasDown(false) {};

			void update()
			{
				if(glfwGetMouseButton(index) && !wasDown)
				{
					action();
					wasDown = true;
				}
				else
				{
					wasDown = false;
				}
			}
	};
}

#endif


